package user.mq;

import api.domain.dto.JudgeSubmitDTO;
import core.enums.ResultCode;
import core.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import mq.RabbitMqConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class JudgeProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    public void produceMsg(JudgeSubmitDTO judgeSubmitDTO) {
        log.info("send message:{}", judgeSubmitDTO);
        try {
            rabbitTemplate.convertAndSend(RabbitMqConstant.OJ_WORK_QUEUE, judgeSubmitDTO);
        } catch (Exception e){
            log.error("rabbit produce msg error", e);
            throw new ServiceException(ResultCode.FAIL_RABBITMQ_PRODUCE);
        }
    }
}
